package com.example.common.resp;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Response {

    /**
     * 状态码 0 表示成功，1表示处理中，-1表示失败
     */
    private Integer code;
    /**
     * 数据
     */
    private Object data;
    /**
     * 描述
     */
    private String msg;

    /**
     * 成功，传入数据
     */
    public static Response buildSuccess() {
        return new Response(0, null, null);
    }

    /**
     * 成功，传入数据
     */
    public static Response buildSuccess(Object data) {
        return new Response(0, data, null);
    }

    /**
     * 成功，传入数据
     */
    public static Response buildSuccess(Integer code,Object data,String msg) {
        return new Response(code, data, msg);
    }

    /**
     * 成功，传入描述信息
     */
    public static Response buildSuccess(String msg) {
        return new Response(0, null, msg);
    }

    /**
     * 失败，传入描述信息
     */
    public static Response buildError(String msg) {
        return new Response(-1, null, msg);
    }

    /**
     * 失败，传入描述信息,状态码
     */
    public static Response buildError(String msg, Integer code) {
        return new Response(code, null, msg);
    }
}
